/*
 * @Date: 2021-08-14 18:26:06
 * @information: 封装返回格式
 */
const globalRes = require('../utils/globalRes')

module.exports = {
  success: function () {
    return async (ctx, next) => {
      ctx.rest = (data) => {
        ctx.response.type = 'application/json'
        ctx.response.body = globalRes.successRes(data)
      }

      try {
        await next()
      } catch (error) {
        ctx.response.body = globalRes.failRes(error.message || error, error.code || null)
      }
    }
  }
}